home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1175 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: alt.msdos.programmer,comp.lang.c
  4. Subject: Re: Pascal program works but not C program!
  5. Date: 11 Jan 1996 17:39:46 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4d4742$n50@solutions.solon.com>
  8. References: <4cdpr2$psi@lugb.latrobe.edu.au> <4cp3vc$8nh@brahms.tfi.be> <4cpqt6$9r8@solutions.solon.com> <4d3scf$4uk@gap.cco.caltech.edu>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4d3scf$4uk@gap.cco.caltech.edu>,
  12. Gary E. Ansok <ansok@alumnae.caltech.edu> wrote:
  13. >Implementations are free to accept other declarations of main().  Indeed,
  14. >the Rationale (not strictly part of the Standard, of course) says (p. 11)
  15. >"While many implementations support more than two arguments to main, such
  16. >practice is neither blessed nor forbidden by the Standard; a program that
  17. >defines main with three arguments is not _strictly conforming_."
  18.  
  19. >So your program is not erroneous if it expects three arguments to main(),
  20. >as long as your compiler accepts it.  It just isn't necessarily portable
  21. >to any other system (or compiler).
  22.  
  23. Which is to say, it is no longer strictly conforming, which is to say, it's
  24. not really C anymore.  A merely "conforming" program (one acceptable to
  25. at least *one* conforming C compiler) could be in FORTRAN; as long as the
  26. compiler gives at least one warning, it can translate anything it wants.
  27.  
  28. The key is that the use of a non-standard declaration of main, just like
  29. the use of strdup(), introduces "undefined behavior".
  30.  
  31. On at least one implementation I know of, you can use "gets(NULL)" as
  32. a way to check a line of input without using a variable.  This is
  33. also conforming code, and is *EXACTLY* as legal as "void main(void)" or
  34. "int main(argc, argv, envp) char **argv, **envp;".
  35.  
  36. >So if you find a compiler that won't accept "int main(int, char **)",
  37. >you have grounds for a complaint.  If your compiler won't accept
  38. >"void main(int, char **, char **)", tough.  You're SOL unless there
  39. >is some other standard (like POSIX, perhaps) that requires it -- then
  40. >your program is limited to systems covered by that other standard.
  41.  
  42. Exactly; although, as I recall, POSIX does not support or encourage void
  43. main, and envp has been deprecated in favor of the extern char *[]
  44. environ.
  45.  
  46. >Yes, I think programmers should remove unnecessary non-portabilities
  47. >from their code.  No, I don't think "void main()" should be the instant
  48. >flame-trigger it seems to be.
  49.  
  50. I think it makes sense in a *C* newsgroup.  If you write conforming code,
  51. you are SOL, and you may be making it gratuitously hard for people to help
  52. you with your problems.  In general, problems with code that is not legit
  53. ANSI are hardly ever problems having to do with the C language; they are
  54. often problems with a given compiler or implementation, which means, they
  55. should be addressed in a newsgroup more related to that implementation.
  56.  
  57. -s
  58. -- 
  59. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  60. C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
  61. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  62. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  63.